﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Core;

namespace DataAccess
{
    public class InfoSinhVien
    {
        private string _MSSV;

        public string MSSV
        {
            get { return _MSSV; }
            set { _MSSV = value; }
        }
        private string _HoTenSV;

        public string HoTenSV
        {
            get { return _HoTenSV; }
            set { _HoTenSV = value; }
        }
        private string _GioiTinh;

        public string GioiTinh
        {
            get { return _GioiTinh; }
            set { _GioiTinh = value; }
        }
        private DateTime _NgaySinh;

        public DateTime NgaySinh
        {
            get { return _NgaySinh; }
            set { _NgaySinh = value; }
        }
        private string _SoDT;

        public string SoDT
        {
            get { return _SoDT; }
            set { _SoDT = value; }
        }
        private string _Email;

        public string Email
        {
            get { return _Email; }
            set { _Email = value; }
        }
        private string _DiaChi;

        public string DiaChi
        {
            get { return _DiaChi; }
            set { _DiaChi = value; }
        }
        private int _TCTL;

        public int TCTL
        {
            get { return _TCTL; }
            set { _TCTL = value; }
        }
        private float _TBCHI;

        public float TBCHI
        {
            get { return _TBCHI; }
            set { _TBCHI = value; }
        }
        private string _LamDA_KhoaLuan;

        public string LamDA_KhoaLuan
        {
            get { return _LamDA_KhoaLuan; }
            set { _LamDA_KhoaLuan = value; }
        }
        private string _MaNganh;

        public string MaNganh
        {
            get { return _MaNganh; }
            set { _MaNganh = value; }
        }
        public string Nganh
        {
            get
            {
                try
                {
                    return InfoNganh.TimTheoMaNganh(this.MaNganh)[0].TenNganh;
                }
                catch
                {
                    return "";
                }
 
            }

        }
     
        private string _MaLop;

        public string MaLop
        {
            get { return _MaLop; }
            set { _MaLop = value; }
        }
        public string Lop
        {
            get
            {
                try
                {
                    return InfoLop.TimLopTheoMa(this.MaLop)[0].TenLop;
                }
                catch
                {
                    return "";
                }
            }
        }
        public InfoSinhVien()
        { }
        public static List<InfoSinhVien> DanhSachSinhVien()
        {
            return CBO.FillCollection<InfoSinhVien>(DataProvider.Instance.ExecuteReader("SinhVien_Select"));
        }
        //Them mot sinh vien
        public static int AddSinhVien(InfoSinhVien infosinhvien)
        {
            return DataProvider.Instance.ExecuteNonquery("SinhVien_Add", infosinhvien.MSSV, infosinhvien.HoTenSV, infosinhvien.GioiTinh, infosinhvien.NgaySinh,
                infosinhvien.SoDT, infosinhvien.Email, infosinhvien.DiaChi, infosinhvien.TCTL,infosinhvien.TBCHI,infosinhvien.LamDA_KhoaLuan,infosinhvien.MaNganh,infosinhvien.MaLop);
        }
        // Xoa mot sinh vien
        public static int DeleteSinhVien(string delete)
        {
            return DataProvider.Instance.ExecuteNonquery("SinhVien_Delete", delete);
        }
        //Update mot sinh vien
        public static int UpdateSinhVien(InfoSinhVien infosinhvien)
        {
            return DataProvider.Instance.ExecuteNonquery("SinhVien_Update", infosinhvien.MSSV, infosinhvien.HoTenSV, infosinhvien.GioiTinh, infosinhvien.NgaySinh,
                infosinhvien.SoDT, infosinhvien.Email, infosinhvien.DiaChi, infosinhvien.TCTL, infosinhvien.TBCHI, infosinhvien.LamDA_KhoaLuan, infosinhvien.MaNganh, infosinhvien.MaLop);
        }
        //Tim kiem sinh vien theo ma
        public static List<InfoSinhVien> TimKiemSinhVienTheoMa(string ma)
        {
            return CBO.FillCollection< InfoSinhVien >(DataProvider.Instance.ExecuteReader("SinhVien_TimKiemMa", ma));
        }
        //TIm kiem sinh vien theo ten
        public static List<InfoSinhVien> TimKiemSinhVienTheoTen(string hoten)
        {
            return CBO.FillCollection<InfoSinhVien>(DataProvider.Instance.ExecuteReader("SinhVien_TimKiemHoTen", hoten));
        }
        //Tim kiem sinh vien theo Email
        public static List<InfoSinhVien> TimKiemSinhVienTheoEmail(string email)
        {
            return CBO.FillCollection<InfoSinhVien>(DataProvider.Instance.ExecuteReader("SinhVien_TimKiemEmail", email));
        }
        //Tim kiem sinh vien theo DoAn
        public static List<InfoSinhVien> TimKiemSinhVienTheoDoAn(string doan)
        {
            return CBO.FillCollection<InfoSinhVien>(DataProvider.Instance.ExecuteReader("SinhVien_TimKiemDoAn", doan));
        }
        //Tim kiem sinh vien theo Nganh
        public static List<InfoSinhVien> TimKiemSinhVienTheoTenNganh1(string tennganh)
        {
            return CBO.FillCollection<InfoSinhVien>(DataProvider.Instance.ExecuteReader("SinhVien_TimKiemTenNganh", tennganh));
        }

        /////// Thong ke
        // Thong ke so luong gia vien theo ma
        public static int ThongKeTheoMaSV()
        {
            object result = DataProvider.Instance.ExecuteScalar("SinhVien_ThongKeMa");
            return Convert.ToInt32(result);
        }
        //Thong ke theo ho ten
        public static int ThongKeTheoHoTenSV(string hoten)
        {
            object result = DataProvider.Instance.ExecuteScalar("SinhVien_ThongKeHoTen", hoten);
            return Convert.ToInt32(result);
        }
        //Thong ke theo dia chi
        public static int ThongKeTheoDoAnKhoaLuan(string doankhoaluan)
        {
            object result = DataProvider.Instance.ExecuteScalar("SinhVien_ThongKeDoAnKhoaLuan", doankhoaluan);
            return Convert.ToInt32(result);
        }

        public static int ThongKeTheoLop(string lop)
        {
            object result = DataProvider.Instance.ExecuteScalar("SinhVien_TimThongKeLop", lop);
            return Convert.ToInt32(result);
        }

        public static int ThongKeTheoNganhn(string nganh)
        {
            object result = DataProvider.Instance.ExecuteScalar("SinhVien_TimThongKeTenNganh", nganh);
            return Convert.ToInt32(result);
        }
        //public static bool KiemTraMa(string ma)
        //{
        //    object rs = DataProvider.Instance.ExecuteScalar("SinhVien_KiemTraMaSo", ma);
        //    return Convert.ToBoolean(rs);
                    
        //}
    }
}
